package com.wuseguang.springcloud.dao.jdbc;

import com.wuseguang.springcloud.JdbcTemplate.BaseTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class SaveAttendJdbc extends BaseTemplate {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public List<Map<String, Object>> queryAttendListMap(String sql, Object... args) {
        logger.info("SaveAttendJdbc==>queryAttendListMap,sql={}", sql);
        return dao.query(sql, args, rs -> {
            List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
            while (rs.next()) {
                Map<String, Object> map = new HashMap<String, Object>();
                int tid = rs.getInt("tid");
                map.put("tid", tid);
                map.put("attend_group_id", rs.getString("attend_group_id"));
                map.put("shift_id", rs.getString("shift_id"));
                map.put("attendtime", rs.getString("attendtime"));
                map.put("attendtype", rs.getString("attendtype"));
                list.add(map);
            }
            logger.info("SaveAttendJdbc==>queryAttendListMap,maps={}", list.toString());
            return list;
        });
    }

    public Map<String, Map<String, String>> getMapShift(String sql) {
        return dao.query(sql, rs -> {
            Map<String, Map<String, String>> maps = new HashMap<String, Map<String, String>>();
            while (rs.next()) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("type", rs.getString("type"));//考勤类型:0 1天1次、1 1天2次
                map.put("starttime", rs.getString("starttime"));
                map.put("endtime", rs.getString("endtime"));
                map.put("starttime1", rs.getString("starttime1"));
                map.put("endtime1", rs.getString("endtime1"));
                maps.put(rs.getString("id"), map);
            }
            logger.info("AttendJdbc==>getMapShift,maps={}", maps.toString());
            return maps;
        });
    }


    public Map<String, Map<String, String>> queryAttendMap(String sql, Object... args) {
        logger.info("AttendJdbc==>queryAttendListMap,sql={}", sql);
        return dao.query(sql, args, rs -> {
            Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
            while (rs.next()) {
                HashMap<String, String> stringStringHashMap = new HashMap<>();
                String userid = rs.getString("userid");
                String time = rs.getString("time");
                String id = rs.getString("id");
                stringStringHashMap.put("time", time);
                stringStringHashMap.put("id", id);
                map.put(userid, stringStringHashMap);
            }
            return map;
        });
    }
}
